<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
    <!-- 引入bootstrap的css -->
    <link rel="stylesheet" href="../js/bootstrap/bootstrap3/css/bootstrap.css">
    <link rel="stylesheet" href="../js/bootstrap/bootstrap3/css/bootstrap-theme.css">
    <!-- 引入jquery的js -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <!-- 引入bootstrap的js -->
    <script type="text/javascript" src="../js/bootstrap/bootstrap3/js/bootstrap.js"></script>

    <!-- 引入boostrap的表格的css、js -->
    <link rel="stylesheet" href="../js/bootstrap/bootstrap-table/bootstrap-table.css">
    <script type="text/javascript" src="../js/bootstrap/bootstrap-table/bootstrap-table.js"></script>
    <script type="text/javascript" src="../js/bootstrap/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <!-- 引入bootbox弹框的js -->
    <script type="text/javascript" src="../js/bootstrap/bootstrap-bootbox/bootbox.js"></script>

    <!-- 引入bootstrap的日期的css、js -->
    <link rel="stylesheet" href="../js/bootstrap/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css">
    <script type="text/javascript" src="../js/bootstrap/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="../js/bootstrap/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
    <!-- 引入fileinput 文件上传的 css、js -->
    <link rel="stylesheet" href="../js/bootstrap/bootstrap-fileinput/css/fileinput.css">
    <script type="text/javascript" src="../js/bootstrap/bootstrap-fileinput/js/fileinput.js"></script>
    <script type="text/javascript" src="../js/bootstrap/bootstrap-fileinput/js/locales/zh.js"></script>

<body>
       <span id="but"></span>

      <div id="sss" style="margin: 50px">


      </div>

<input type="hidden"  value="0" id="daa">


</body>

   <script th:inline="javascript">

       function bv(){
            alert("点赞")
       }

       $(function(){
           //显示按钮
           butt();

           //查询影厅数量
           hallCount();

           //查询播放计划
           queryPlan(0);

       })

       //查询播放计划
       function queryPlan(num){

           //查询影厅数量
           hallCount();

           var dateTime=new Date();
           dateTime=dateTime.setDate(dateTime.getDate()+num);
           dateTime=new Date(dateTime).toLocaleString();

           $.ajax({
               url:"../plan/queryPlan",
               type:"get",
               data:{dateTime:dateTime,id:[[${session.user.cinemaId}]]},
               async:false,
               success:function(data) {
                   for (var i = 0; i < data.length; i++) {
                      var hallid= data[i].hallid;
                      var playid= data[i].playid;
                      var sid= "s"+playid+""+hallid;
                      $("#"+sid+"").html(data[i].movieName);

                   }
               }
           })

           $("#daa").val(num)

       }




       function butt(){
           var dateTime=new Date();

           var str='<button onclick="queryPlan(0)" class="btn btn-primary " type="button">今日</button>';
           for (var i = 1; i <= 3; i++) {
               var dateTime=new Date();
               dateTime=dateTime.setDate(dateTime.getDate()+i);
               dateTime=new Date(dateTime);
               var yue = dateTime.getMonth()+1+'月'+dateTime.getDate()+'日';
             str+='<button onclick="queryPlan('+i+')" class="btn btn-primary " type="button">'+yue+'</button>';
           }
           $("#but").html(str)
       }



      function hallCount(){
           $.ajax({
               url:"../plan/hallCount",
               type:"get",
               data:{id: [[${session.user.cinemaId}]]},
               async:false,
               success:function(data){
                   var str='<table class="table table-hover  table-striped" >';

              str+=' <tr class="warning"><td></td>' +
                  '<td>8:00</td>' +
                  '<td>10:00</td>' +
                  '<td>12:00</td>' +
                  '<td>15:00</td>' +
                  '<td>20:00</td>'+
              '</tr>';
                   for (var i = 0; i < data.length; i++) {

                      str+=' <tr class="success">';
                          str+=' <td class="info">'+data[i].hallname+'</td>';

                       for (var j = 1; j <= 5; j++) {
                                 str+=  '<td id="s'+j+data[i].hallId+'">' +
                                              '<button onclick="arrange('+j+','+data[i].hallId+',\''+data[i].hallname+'\')" class="btn btn-primary " type="button">安排放映</button>'+
                                         '</td>';
                       }

                      str+='</tr> ';
                   }
                   str+='</table>';
                   $("#sss").html(str);
              }
           })
      }

       //合并页面
       var res;
       function createAddContent(url){
           $.ajax({
               url:url,
               async:false,//同步
               success:function(data){
                   res = data;
               }
           });
           return res;
       }

       //添加电影安排
       function arrange(playid,hallId,name){
           var data=$("#daa").val();
           bootbox.dialog({
               title:'修改信息',
               message: createAddContent("../planPage/addplay?playid="+playid+"&hallId="+hallId+"&data="+data),//合并页面
               closeButton: true,
               buttons : {
                   "success" : {
                       "label" : "<i class='icon-ok'></i> 保存",
                       "className" : "btn-sm btn-success",
                       "callback" : function() {//回调函数
                           //提交表单
                           $.ajax({
                               url:"../plan/addplay",
                               type:'post',
                               data:$("#addForm").serialize(),//表单序列化
                               async:false,
                               success:function(){
                                   //刷新表格
                                   var data=$("#daa").val();
                                   var a=parseInt(data);
                                   queryPlan(a)

                               }
                           });
                       }
                   },
                   "cancel" : {
                       "label" : "<i class='icon-info'></i> 取消",
                       "className" : "btn-sm btn-danger"
                   }
               }

           })
                   $("#name").html(name);


           var sd=new Date().toLocaleDateString();
          if(playid==1){
               sd+=" &thinsp;&thinsp;&thinsp; 8:00"
             $("#md").val("8:00");
           }
           else if(playid==2){
               sd+=" &thinsp;&thinsp;&thinsp; 10:00"
              $("#md").val("10:00");
           }
           if(playid==3){
               sd+=" &thinsp;&thinsp;&thinsp; 12:00"
               $("#md").val("12:00");
           }
           else if(playid==4){
               sd+=" &thinsp;&thinsp;&thinsp; 15:00"
               $("#md").val("15:00");
           }
           if(playid==5){
               sd+=" &thinsp;&thinsp;&thinsp; 20:00"
               $("#md").val("20:00");
           }
           $("#dates").html(sd);




       }

   </script>




</html>